package cn.tuling.example;

/**
 * 包
 * 按种类分为挎包、钱包
 * 按颜色分为红色、黄色
 * 按不同维度可进行不同的抽象，为了隔离两种抽象的变化，使用桥接模式
 */
public class BridgeExampleTest {
    public static void main(String[] args) {
        Color red = new Red();
        Bag bag = new Wallet(red);
        bag.getName();
    }
}

interface Color {
    String getColor();
}

class Yellow implements Color {

    @Override
    public String getColor() {
        System.out.println("我是黄色");
        return "Yellow";
    }
}

class Red implements Color {
    @Override
    public String getColor() {
        System.out.println("我是红色");
        return "Red";
    }
}

abstract class Bag {
    protected Color color;

    protected Bag(Color color) {
        this.color = color;
    }

    abstract public String getName();
}

class HandBag extends Bag {

    protected HandBag(Color color) {
        super(color);
    }

    @Override
    public String getName() {
        System.out.println(color.getColor() + " 挎包");
        return "HandBag";
    }
}

class Wallet extends Bag {

    protected Wallet(Color color) {
        super(color);
    }

    @Override
    public String getName() {
        System.out.println(color.getColor() + " 钱包");
        return "Wallet";
    }
}